package top.tangyh.lamp.care.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import top.tangyh.basic.base.mapper.SuperMapper;
import top.tangyh.lamp.care.entity.BDevDetail;
import org.springframework.stereotype.Repository;
import top.tangyh.lamp.care.vo.query.DevDetailSearchVO;
import top.tangyh.lamp.care.vo.result.DevDetailDto;

import java.util.List;

import static top.tangyh.lamp.common.constant.CommonConstant.NO_NUMBER;

/**
 * <p>
 * Mapper 接口
 * 监护仪设备详情表
 * </p>
 *
 * @author zqb
 * @date 2024-07-15 16:42:41
 * @create [2024-07-15 16:42:41] [zqb] [代码生成器生成]
 */
@Repository
public interface BDevDetailMapper extends SuperMapper<BDevDetail> {

    List<DevDetailDto> selectPageOfDevicesByParam(DevDetailSearchVO query);

    int selectCountOfBindDev(String devCode);

    default BDevDetail selectOneByDevCode(String devCode) {
        LambdaQueryWrapper<BDevDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BDevDetail::getDevCode, devCode)
                .eq(BDevDetail::getIsDeleted, NO_NUMBER);
        return this.selectOne(queryWrapper);
    }

    default List<BDevDetail> selectListByDevCode(List<String> allDevCode) {
        LambdaQueryWrapper<BDevDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(BDevDetail::getDevCode, allDevCode)
                .eq(BDevDetail::getIsDeleted, NO_NUMBER);
        return this.selectList(queryWrapper);
    }

    default List<BDevDetail> selectListByDevCode(String devCode) {
        LambdaQueryWrapper<BDevDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BDevDetail::getDevCode, devCode)
                .eq(BDevDetail::getIsDeleted, NO_NUMBER);
        return this.selectList(queryWrapper);
    }

    default int getCountByDevCode(String devCode) {
        // 创建 LambdaQueryWrapper，并指定查询条件
        LambdaQueryWrapper<BDevDetail> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(BDevDetail::getDevCode, devCode)
        .eq(BDevDetail::getIsDeleted, NO_NUMBER);
        // 使用 count() 方法获取匹配的记录数量
        return Math.toIntExact(this.selectCount(queryWrapper));
    }
}


